# Contributor: Jakob Meier <comcloudway@ccw.icu>
# Maintainer: Jakob Meier <comcloudway@ccw.icu>
pkgname=welle-io
pkgver=2.5
pkgrel=0
pkgdesc="A DAB/DAB+ Software Defined Radio (SDR)"
url="https://www.welle.io/"
arch="all"
license="GPL-2.0-or-later"
# potentally missing: airspy-dev
makedepends="
	cmake
	faad2-dev
	fftw-dev
	lame-dev
	librtlsdr-dev
	mpg123-dev
	qt6-qtbase-dev
	qt6-qtcharts-dev
	qt6-qtdeclarative-dev
	qt6-qtmultimedia-dev
	qt6-qttools-dev
	samurai
	soapy-sdr-dev
	alsa-lib-dev
	"
subpackages="$pkgname-doc welle-cli:cli"
source="welle-$pkgver.tar.gz::https://github.com/AlbrechtL/welle.io/archive/refs/tags/v$pkgver.tar.gz"
builddir="$srcdir/welle.io-$pkgver"

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	# DCMAKE_EXE_LINKER_FLAGS required,
	# to prevent segfault when trying to interact with device
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=None \
		-DRTLSDR=ON \
		-DSOAPYSDR=ON \
		-DCMAKE_EXE_LINKER_FLAGS=-Wl,-z,stack-size=512000 \
		$CMAKE_CROSSOPTS
	cmake --build build
}

check() {
	cd build
	CTEST_OUTPUT_ON_FAILURE=TRUE ctest
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

cli() {
	pkgdesc="$pkgdesc (cli frontend)"
	amove usr/bin/welle-cli
}

sha512sums="
ec82a38daac77e81db83c5d90cc508be2eadf8308496f4bfa210b72351a763e8944bac2f05c5a24302d771632b0b2cd729ceb277278f7cd0b930f99c0856d03f  welle-2.5.tar.gz
"
